<template>
  <header id="header">
    <div class="header" ref="header">
      <div class="header-top">
        <img src="@/assets/fantu-logo.png" @click="toHome" alt="梵途logo" />

        <ul class="flex header-ul">
          <li
            v-for="(value,index) in listRenderingLists"
            :key="value.text"
            @click="onclick(index)"  :class=" [{active:$store.state.topFlag==index}] "
          >{{value.text}}</li>
          <li @click="addAppNumFuc" ref="liAppNum">下载APP</li>
          <li @click="routerWeb">智慧物流后台</li>
        </ul>
      </div>
      <!-- 下载app的弹框 start -->
      <div
        v-if="appNum"
        class="appNum-flex"
        style="width:100%;position:absolute;top:0;height:61rem;background-color:rgba(0,0,0,0.7);z-index:999999999"
      >
        <div class="appNum-flex" style="width:100%;position:absolute;height:52.5rem;">
          <div class="appNum-flex-big-box">
            <div class="appNum-flex-box-line"></div>
            <div class="appNum-flex-box-close">
              <img @click="removeAppNumFuc" src="@/assets/header/header-close.png" alt />
            </div>
            <div class="appNum-flex" style="width:100%;height:18rem;margin-top:3%;">
              <div class="appNum-flex" style="width:34.8rem;height:18rem;">
                <div class="appNum-flex" style="width:17.4rem;height:18rem;flex-direction: column">
                  <p class="appNum-flex-box-p">“哆啦快运”APP</p>
                  <img
                    style="width:6.7rem;height:2.875rem"
                    src="@/assets/header/header-shipper.png"
                    alt
                  />
                  <div style="margin-top:0.7rem">
                    <img
                      style="width:10.625rem;height:10.625rem"
                      src="@/assets/product/product-shipper-code.png"
                      alt
                    />
                  </div>
                  <p style="color:#333;">安卓货主端</p>
                </div>
                <div class="appNum-flex" style="width:17.4rem;height:18rem;flex-direction: column">
                  <P class="appNum-flex-box-p">“哆啦快运”APP</P>
                  <img
                    style="width:6.7rem;height:2.875rem"
                    src="@/assets/header/header-driver.png"
                    alt
                  />
                  <div style="margin-top:0.7rem">
                    <img
                      style="width:10.625rem;height:10.625rem"
                      src="@/assets/product/product-driver-code.png"
                      alt
                    />
                  </div>
                  <p style="color:#333;">安卓司机端</p>
                </div>
              </div>
            </div>
            <p
              style="color:#F17C70;text-align:center;margin-top:3.9rem"
            >（注：IOS请直接在APP STORE搜索“哆啦快运“货主端或者搜索”哆啦快运“司机端进行下载）</p>
          </div>
        </div>
      </div>
    </div>
    <!-- 下载app的弹框end -->

    <!-- 下拉框的选项 -->
    <div
      v-if="showBox"
      class="option-menu"
      style="position: fixed;top:3.72rem;display:flex;margin-left: 26.5%;width:60%;z-index:99999999"
    >
      <ul class="hide" v-bind:class="[{show:show==0}]" @mouseleave="leave()">
        <li @click="link('#home-aboutUs')">公司简介</li>
        <li @click="link('#home-future')">盈利模式</li>
        <li @click="link('#home-our-word')">发展目标</li>
      </ul>

      <ul class="hide" v-bind:class="[{show:show==1}]" @mouseleave="leave()">
        <li @click="link('#product-web')">智慧物流管理Web</li>
        <li @click="link('#product-shipper')">"哆啦快运"APP货主端</li>
        <li @click="link('#product-driver')">"哆啦快运"APP司机端</li>
      </ul>

      <ul class="hide" v-bind:class="[{show:show==2}]" @mouseleave="leave()">
        <li @click="changeNum(0)">查看全部岗位</li>
        <li @click="changeNum(1)">技术岗位</li>
        <li @click="changeNum(2)">服务岗位</li>
      </ul>
    </div>
  </header>
</template>
<script>
export default {
  name: "Header",
  data() {
    return {
      listRenderingLists: [
        { text: "品牌" },
        { text: "产品" },
        { text: "招贤纳士" },
        { text: "政企业务" }
      ],
      isActive: false,
      dynamic: -1,
      appNum: false,
      showBox: false,
      show: -1
    };
  },
  methods: {
    //选中菜单调转路由并且控制下拉菜单的显示和隐藏
    onclick: function(index) {
      this.dynamic = index;
      this.show = index;
      this.showBox = true;
      this.changetopFlag(index);
      if (index == 0) {
        this.$router.push({
          name: "home"
        });
      } else if (index == 1) {
        this.$router.push({
          name: "product"
        });
      } else if (index == 2) {
        this.$router.push({
          name: "recruit"
        });
      } else if (index == 3) {
        this.$router.push({
          name: "business"
        });
        this.showBox = false;
      }
    },
    //点击跳转相应的锚点
    link(link) {
      document.querySelector(link).scrollIntoView(true);
    },
    //改变全局topFlag控制选中的样式
    changetopFlag(num) {

      this.$store.state.topFlag = num;
    },
    //职位招聘的切换
    changeNum(num) {
      this.$store.state.changeNum = num;
      console.log("qiehuan")
      this.login();
    },
    //下拉菜单移出区域隐藏
    leave() {
      this.show = -1;
      this.showBox = false;
    },
    //下载app的显示以及css样式
    addAppNumFuc() {
      this.show = -1;
      this.appNum = true;
      this.$refs.liAppNum.classList.add("li-active");
    },
    //下载app的隐藏以及css的移除
    removeAppNumFuc() {
      this.appNum = false;
      this.$refs.liAppNum.classList.remove("li-active");
    },
    //点击智慧物流平台打开新网址
    routerWeb() {
      window.open("http://admin.fantudl.com");
    },
    //监听滑动区域，增加header组件的阴影样式
    handleScrollHeader() {
      var scrollTop =
        window.pageXOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop > 800) {
        this.$refs.header.classList.add("header-shadow");
      } else {
        this.$refs.header.classList.remove("header-shadow");
      }
    },
    //点击图标返回首页
    toHome() {
      this.$router.push({
        name: "home"
      });
      this.changetopFlag(0);
    }
  },
  created() {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem("store"))
        )
      );
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    });
  },
  //页面挂载后侦听滑动事件
  mounted() {
    window.addEventListener("scroll", this.handleScrollHeader);
  }
};
</script>

<style scoped>
.header {
  background-color: #333333;
  height: 3.7125rem;
  color: #ffffff;
  font-size: 14px;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99999;
  border-bottom: 0.05rem solid #eae9e9;
}
.header-top {
  width: 100%;
  height: 3.7125rem;
  background-color: #fff !important;
  color: #333;
  display: flex;
  align-items: center;
}
.header-top img {
  width: 7.5rem;
  height: 1.875rem;
  margin-left: 18.7%;
  cursor: pointer;
}

.home-active-img img {
  width: 10.375rem;
  height: 0.5rem;
}
.home-active-img img:nth-of-type(1) {
  margin-left: 26.3%;
}
.header-ul {
  height: 3.7125rem;
}
ul {
  margin-block-start: 0;
  margin-block-end: 0;
  padding-inline-start: 0;
  width: 70%;
}
ul li {
  text-align: center;
}
.flex {
  display: flex;
}
.flex > li {
  font-size: 0.875rem;
  width: 10%;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  font-weight: bold;
  padding: 1.125rem 0.95rem;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-self: center;
}
.flex > li:nth-of-type(1) {
  margin-left: 2%;
}
.flex > li:nth-of-type(5) {
  margin-left: 10.3%;
  border: 1px solid #979797;
  width: 6.3%;
  font-size: 0.875rem;
  line-height: 1.5rem;
  vertical-align: middle;
  padding: 0;
  font-weight: normal;
  border-radius: 3px;
  font-size: 0.875rem;
  color: #333;
}
.flex > li:nth-of-type(5):hover {
  color: #333;
}
.flex > li:nth-of-type(6) {
  margin-left: 0.6%;
  font-weight: normal;
  font-size: 0.875rem;
  color: #333;
}
.flex > li:hover {
  color: #3eadff;
  /* border-bottom: 3px solid #3EADFF; */
}
.option-menu ul {
  width: 14.2%;
  background-color: #fff;
  box-shadow: 0px 1px 2px 0px rgb(201, 202, 202);
  padding: 0.5rem 0;
}

.option-menu ul li {
  font-size: 0.875rem;
  line-height: 2.4rem;
}
.option-menu ul li:hover {
  color: #2fa9de;
  cursor: pointer;
}
.hide {
  z-index: -99999;
  opacity: 0;
}
.show {
  z-index: 9999;
  opacity: 1;
}
.header-bottom-box >>> li:hover {
  color: #2fa9de;
}
.header-bottom {
  position: absolute;
  top: 55px;
  width: 100%;
  height: 3.875rem;
  background-color: #f7f7f7;
  z-index: 9999;
}
.header-bottom-box {
  width: 57%;
  margin: 0 auto;
  background-color: #f7f7f7;
  height: 3.875rem;
  z-index: 9999;
  display: flex;
  align-items: center;
  color: #333333;
}
.header-bottom-box img {
  width: 136px;
  height: 33px;
}
/* 品牌 */
.brand {
  margin-left: 7%;
  width: 30%;
}
.brand li {
  font-size: 1rem;
  margin-left: 5%;
  width: 100%;
}
/* 产品 */
.product {
  width: 55%;
  margin-left: 7%;
}
.product li {
  font-size: 1rem;
  width: 60%;
}
/* 招聘 */
.recruit {
  width: 35%;
  margin-left: 7%;
}
.recruit li {
  font-size: 1rem;
  width: 50%;
}

/* app下载弹框的效果 */
.appNum-flex {
  display: flex;
  justify-content: center;
  align-items: center;
}
.appNum-flex-big-box {
  width: 50.375rem;
  height: 34.25rem;
  background-color: #fff;
  box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, 0.32);
  z-index: 99999;
}
.appNum-flex-box-line {
  width: 100%;
  height: 6px;
  background: linear-gradient(to right, #3ac4f2, #0e54f1);
  opacity: 0.8;
}
.appNum-flex-box-close {
  height: 4rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background-color: #fff;
}
.appNum-flex-box-close img {
  width: 21px;
  height: 21px;
  padding: 1.5rem 1.8rem 1.5rem 1.5rem;
  cursor: pointer;
}
.appNum-flex-box-p {
  color: #333;
  font-size: 1.625rem;
  font-weight: 600;
}
/* 选中的效果 */
.active {
  /* background-color: red; */
  border-bottom: 3px solid #3eadff;
  color: #3eadff;
}
.li-active {
  color: #3eadff !important;
  border: 1px solid #3eadff !important;
}
.header-shadow {
  box-shadow: 0 0 10px #ccc;
}
</style>
